<%@include file="../init.jspf" %>
<div>

    <portlet:actionURL var="URLtoSubjectList">
        <portlet:param name="action" value="show_subject_list"/>
    </portlet:actionURL>

    <div class="levelUpOption">
        <a href="${URLtoSubjectList}">Watch all subjects</a>
    </div>

    <h4><spring:message code="title"/> <span class="highInTitle"><c:out value="${subject}"/></span></h4>

    <table class="subjectExamsOverviewTable">
        <tr>
            <th><spring:message code="table.date"/></th>
            <th><spring:message code="table.time"/></th>
            <th><spring:message code="table.daysleft"/></th>
            <th><spring:message code="table.occupied"/></th>
            <th><spring:message code="table.actions"/></th>
        </tr>

        <c:forEach var="exam" items="${exams}">
            <tr>
                <td>${exam.localDate}</td>
                <td>${exam.localTime}</td>
                <td>${exam.dayLeft}</td>
                <td>${exam.occupied}</td>
                <td>
                    <c:if test="${exam.inPast}">
                        <c:if test="${exam.registered}">
                            <spring:message code="table.registered"/>
                        </c:if>
                    </c:if>
                    <c:if test="${!exam.inPast}">
                        <c:if test="${exam.registrationPossible}">
                            <portlet:actionURL var="registerExamUrl">
                                <portlet:param name="action" value="register_exam_action"/>
                            </portlet:actionURL>
                            <form method="post" action="${registerExamUrl}">
                                <input type="hidden" name="examId" value="${exam.examId}"/>
                                <input type="submit" value="<spring:message code="table.actions.register"/>"/>
                            </form>
                        </c:if>
                        <c:if test="${exam.registered}">
                            <portlet:actionURL var="unregisterExamUrl">
                                <portlet:param name="action" value="unregister_exam_action"/>
                            </portlet:actionURL>

                            <form method="post" action="${unregisterExamUrl}">
                                <input type="hidden" name="examId" value="${exam.examId}"/>
                                <input type="submit" value="<spring:message code="table.actions.unregister"/>"/>
                            </form>
                        </c:if>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
    </table>
</div>